import {defineStore} from 'pinia'

const baseInfoStore = defineStore('baseInfo',{
    state:()=>({
        windowWidth: 0,
        windowHeight: 0,
        currentBrand:'', //当前品牌
        lightShowType:[
        ],
        brandList:<{label: string; value: string;}[]>[],
        vehicleTypeList:[],
        carCode:[
        ]
    }),
    actions:{
        updateBrandList(brandList:Array<{ name:string, code:string }> | []){
            if (brandList.length > 0){
                if (!this.currentBrand) this.currentBrand = brandList[0].code
                this.brandList = brandList.map(item => ({
                    label: item.name,
                    value: item.code
                }));
            }else{
                this.brandList = []
            }
        },
        updateCurrentBrand(brandValue:'geely | lynkco | galaxy',){
            this.currentBrand = brandValue
            // 执行页面刷新的逻辑
            location.reload();
        },
        setWindowWidth(width:number, fn:() => void = ()=>{}){
            this.windowWidth = width
            fn()
        },
        setWindowHeight(height:number, fn:() => void = ()=>{}){
            this.windowHeight = height
            fn()
        }
    }
})

export default baseInfoStore